for i in' '*int(input()):
l=[]
g=0
n=int(input())
for i in' '*n:
l.append(input()+'1')
l.append('1'*n)
for x in range(n):
for i in range(n):
if l[x][i]=='1'and not(l[x+1][i]=='1'or l[x][i+1]=='1'):
g=1
print('YNEOS'[g::2])
// Problem: E. Polygon
// Contest: Codeforces - Codeforces Round #644 (Div. 3)
// URL: https://codeforces.com/contest/1360/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
// #pragma GCC optimize("fast-math")
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define vi vector <int>
#define vvi vector <vi>
#define pii pair<int, int>
#define ppi pair<pii, int>
#define vii vector<pii>
#define mii map<int, int>
#define mci map<char, int>
#define miv map<int, vi>
#define mis map<int, set<int>>
#define setbits(n) __builtin_popcount(n)
#define msb(x) __builtin_clz(x)
#define lsb(x) __builtin_ctz(x)
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define in(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define dbg(x) cout << #x << " = " << (x) << endl
#define show2(a, b) cout<<a<<' '<<b<<endl
#define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl
#define show(arr) for (auto i:arr) cout<<i<<' ';
#define Endl endl
const long long N=1e5+5;
const long long mod=1000000007; //998244353;
//always use arrays if you want to coordinate compress.
vvi vis;
vector<string> s;
int n;
bool check(int x, int y)
{
if(x==n || y==n)return true;
if(vis[x][y]!=-1)return vis[x][y];
if(s[x][y]!='1')return vis[x][y]=false;
return vis[x][y]=(check(x+1,y)||check(x,y+1));
}
void cases(){
cin>>n;
s.clear();s.resize(n);in(s,n);
vis.clear();vis.assign(n,vi(n,-1));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(vis[i][j]==1 || s[i][j]=='0')continue;
if(!check(i,j))
{
// show2(i,j);
no;return;
}
}
}
yes;
}
int32_t main(){
std::ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int t=1;
cin>>t;
for (int i=0; i<t; i++){
//cout<<"Case #"<<i+1<<": ";
cases();
}
return 0;
}
702A - Maximum Increase | 1656D - K-good |
1426A - Floor Number | 876A - Trip For Meal |
1326B - Maximums | 1635C - Differential Sorting |
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |
689B - Mike and Shortcuts | 379B - New Year Present |
1498A - GCD Sum | 1277C - As Simple as One and Two |
1301A - Three Strings | 460A - Vasya and Socks |
1624C - Division by Two and Permutation | 1288A - Deadline |
1617A - Forbidden Subsequence | 914A - Perfect Squares |
873D - Merge Sort | 1251A - Broken Keyboard |
463B - Caisa and Pylons | 584A - Olesya and Rodion |
799A - Carrot Cakes | 1569B - Chess Tournament |
1047B - Cover Points | 1381B - Unmerge |